#include "SFC_Inc.hpp"
#include "SFC_Container.h"

SFC_Container::SFC_Container()
{
}

void SFC_Container::LoadRes()
{
	// Create cache surface
	if (this->Cache != nullptr)
		FreeSurface(this->Cache);
	this->Cache = CreateSurface(this->Size.w, this->Size.h);
	FillRect(this->Cache, nullptr, 0xFFDDDDDD);
}

void SFC_Container::EventRouter(SFC_Event &Event)
{
	if (Event.Type == EventType::Window && Event.Window.Type == WindowEventType::Paint)
	{
		Paint();
	}
}

void SFC_Container::Paint()
{
	if (this->Durty == false) return ;

	this->Children.clear();
	LoadRes();
	for (auto obj = this->Container.begin(); obj != this->Container.end(); obj++)
	{
		this->Children.push_back(*obj);
	}

	this->Durty = false;
}